/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
public:
    int deepest = 0;
    int res;
    int findBottomLeftValue(TreeNode* root) {
        dfs(root, 1);
        return res;
    }
    void dfs(TreeNode* root, int cur_depth) {
        if (!root) return;
        if (!root -> left && !root -> right)
        {
            if(cur_depth > deepest)
            {
                deepest = cur_depth;
                res = root -> val;
            }
            return;
        }
        dfs(root -> left, cur_depth + 1);
        dfs(root -> right, cur_depth + 1);
        return;
    }
};
